package bTree.LeetCode;

public class 长按键入 {
    public boolean isLongPressedName(String name, String typed) {
        int left=0,right=0;
        int length1 = name.length();
        int length2 = typed.length();
        while (left!=length1&&right!=length2){
            char c1 = name.charAt(left);
            char c2 = typed.charAt(right);
            if (c1==c2){
                left++;
            }else {
                if (left==0||(left!=0&&c2!=name.charAt(left-1))){
                    return false;
                }
            }
            right++;
        }
        if (left!=length1){
            return false;
        }
        for (int i=right;i<length2;i++){
            if (typed.charAt(i)!=name.charAt(left-1)){
                return false;
            }
        }
        return true;
    }
}